package io.github.gozhuyinglong.autoconfigure;

import io.github.gozhuyinglong.demo.DemoPet;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

/**
 * @author ZhuYinglong
 * @date 2022/2/19 0019
 */
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(DemoProperties.class)
public class DemoAutoConfiguration {

    private final DemoProperties demoProperties;

    public DemoAutoConfiguration(DemoProperties demoProperties) {
        this.demoProperties = demoProperties;
    }

    @Bean
    public DemoPet demoPet() {
        if (!StringUtils.hasText(demoProperties.getType())) {
            return new DemoPet("空的");
        }
        switch (demoProperties.getType()) {
            case "cat":
                return new DemoPet("小猫");
            case "dog":
                return new DemoPet("小狗");
            default:
                return new DemoPet("未知");
        }
    }
}
